package 预习;

import java.util.Scanner;

public class 查找元素在数组中索引位置 {
    public static void main(String[] args) {
       while (true){
           int[] arr = {31, 42, 23, 64, 25, 36, 15, 23, 45, 56, 78, 89, 46, 12};
           Scanner sc = new Scanner(System.in);
           System.out.println("请输入一个整数：");
           int num = sc.nextInt();
           int com = findNum(arr, num);

           System.out.println(com);
       }
    }

    public static int findNum(int[] arr, int num) {

        for (int i = 0; i < arr.length; i++) {
            if (num == arr[i]) {
                return i;
            }
        }
        return -1;
    }
}
